package com.bwhx.eruler.dao.hodo.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.casdilly.BodyItem;
import com.bwhx.eruler.bean.hodo.ClothesSize;
import com.bwhx.eruler.dao.hodo.ClothesSizeDAO;
import com.bwhx.eruler.dao.impl.BaseDaoImpl;

@Repository
public class ClothesSizeDAOImpl extends BaseDaoImpl<ClothesSize>  implements ClothesSizeDAO  {
	
	public ClothesSizeDAOImpl() {
		this.setNs("com.bwhx.eruler.mapper.hodo.ClothesSizeMapper.");
	}

 

	@Override
	public void addComponent(BodyItem resultBeanBodyItem) {
		this.getSqlSession().update(this.getNs() + "addComponent",resultBeanBodyItem);
		
	}


	@Override
	public List<ClothesSize> findConflict(ClothesSize cSize) {
		return   getSqlSession().selectList(this.getNs() + "findConflict", cSize) ;
	}


	@Override
	public List<HashMap<String, String>> detailList(Page p) {
		return   getSqlSession().selectList(this.getNs() + "detailList", p) ;
	}


	@Override
	public Integer detailCount(ClothesSize cSize) {
		return   getSqlSession().selectOne(this.getNs() + "detailCount", cSize) ;
	}


	@Override
	public ClothesSize findByClothesSizeID(String csid) {
 		return getSqlSession().selectOne(this.getNs() + "findByClothesSizeID", csid) ; 
	}


	@Override
	public List<Map<String, String>> findCSDetailBycsID(String csid) {
		
		return   getSqlSession().selectList(this.getNs() + "findCSDetailBycsID", csid) ;
	}



	@Override
	public List<ClothesSize> listAll() {
		return   this.getSqlSession().selectList(this.getNs() + "listAll") ;
	}



	@Override
	public List<Map<String, Object>> findDetailConflict(Map<String, Object> paramMap) {
 		return this.getSqlSession().selectList(this.getNs() + "findDetailConflict",paramMap) ;
	}



	@Override
	public void insertDetail(Map<String, Object> paramMap) {
		
		 paramMap.remove("sizeid");
		
		 List<Object> keyList =Arrays.asList( paramMap.keySet().toArray());
		 List<Object> valueList = new ArrayList<Object>();
		 
		 for (Object key : keyList) {
			 Object object = paramMap.get(key);
			 valueList.add(object);
 		}
		 
		 HashMap<String, Object> paramMap2 = new HashMap<String, Object>();
		 paramMap2.put("key", keyList);
		 paramMap2.put("value", valueList);
		 
		 this.getSqlSession().insert(this.getNs() + "insertDetail",paramMap2);
 		
	}



	@Override
	public void updateDetail(Map<String, Object> paramMap) {
		
		String sizeid = String.valueOf(paramMap.remove("sizeid"));
		
		/*ArrayList<String> paramList = new ArrayList<String>();
		
		Set<String> keySet = paramMap.keySet();
		for (String key : keySet) {
			String value = String.valueOf(paramMap.get(key));
			paramList.add(key+"="+value);
 			
		}*/
		
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		paramMap2.put("sizeinfo", paramMap);
		paramMap2.put("sizeid", sizeid);
		this.getSqlSession().update(this.getNs() + "updateDetail",paramMap2);
	}



	@Override
	public void delDetail(HashMap<String, Object> paramMap) {
		this.getSqlSession().update(this.getNs() + "delDetail",paramMap);
	}

}
 